package com.baizhi.service.impl;

import com.baizhi.dao.NewsDao;
import com.baizhi.entity.News;
import com.baizhi.service.NewsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsDao nd;
    @Override
    @Transactional(readOnly = true)
    public List<News> selectAll() {

        return nd.selectAll();
    }

    @Override
    public PageInfo<News> selectByPage(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<News> news = nd.selectAll();

        return new PageInfo<>(news);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void insert(News news) {
        nd.insert(news);
    }
}
